思路主要来自:http://www.infoq.com/cn/news/2011/03/xxb-maven-5-integration-test/ Maven实战(五)——自动化Web应用集成测试

首先需要在测试前把应用服务器启动起来,并把war包部署到服务器上,这个主要是把jboss-as:startjboss-as:deploy这两个goal绑定到pre-integration-test阶段;另外在测试完之后要把服务器停掉,这个主要把jboss-as:shutdown绑定到post-integration-test阶段

<build>
    <plugin>
        <groupId>org.jboss.as.plugins</groupId>
        <artifactId>jboss-as-maven-plugin</artifactId>
        <version>7.7.Final</version>
        <executions>
            <excution>
                <id>jboss-start-deploy</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>start</goal>
                    <goal>deploy</goal>
                </goals>
                <configuration>
                    <name>${project.artifactId}.${project.packaging}</name>
                </configuration>
            </excution>
            <excution>
                <id>jboss-shutdown</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>shtudown</goal>
                </goals>
            </excution>
        </executions>
    </plugin>
</build>

另外,需要将集成测试的类命名为不含有Test(例如改为以*IT.java命名),否则在单元测试阶段会执行这些测试案例,之后需要将这些测试的执行绑定到integration-test阶段:

<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
        <executions>
            <excution>
                <id>run-integration-test</id>
                <phase>integration-test</phase>
                <goals>
                    <goal>test</goal>
                </goals>
                <configuration>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                </configuration>
            </excution>
        </executions>
    </plugin>
</build>    

青蛙仔爸爸
0 声望0 粉丝